package com.sdkj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdkj.pojo.Orders;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface OrdersMapper extends BaseMapper<Orders> {

    @Select("SELECT COUNT(o.setmealid)AS value, s.name  FROM orders o,setmeal s WHERE o.`setmealid`=s.`id` GROUP BY setmealid")
    public List<Map<String,Object>> getSetmealNameAndCount();


    @Select("SELECT COUNT(*) FROM orders WHERE orderdate=#{today}")
    public Integer getTodayOrderInfo(@Param("today") String str);


    @Select("SELECT COUNT(*) FROM orders WHERE orderstatus='已到诊' and orderdate=#{today}")
    public Integer getTodayVisitsNumber(@Param("today") String str);



    @Select("SELECT COUNT(*) FROM orders WHERE orderdate between #{begin} and #{end}")
    public Integer getOrderInfo(@Param("begin") String begin,@Param("end") String end);


    @Select("SELECT COUNT(*) FROM orders WHERE orderstatus='已到诊' and orderdate between #{begin} and #{end} ")
    public Integer getVisitsNumber(@Param("begin") String begin,@Param("end") String end);

    @Select("SELECT \n" +
            "  s.name,\n" +
            "  s.remark,\n" +
            "  COUNT(o.id) AS setmeal_count,\n" +
            "  COUNT(o.id) / \n" +
            "  (SELECT \n" +
            "    COUNT(*) \n" +
            "  FROM\n" +
            "    orders) AS proportion \n" +
            "FROM\n" +
            "   orders o INNER JOIN setmeal s  ON o.setmealid = s.id GROUP BY o.setmealid\n" +
            "   ORDER BY setmeal_count DESC LIMIT 0,2")
    public List<Map<String,Object>> getHotSetmeal();
}
